<template>
<section class="page page-theme reg-page">
  <header class="page-header">
    <router-link class="btn-close" to="/">
      <i class="el-icon-close"></i>
    </router-link>
  </header>

  <h2 class="current-title">找回密码</h2>

  <div class="form-waper">
    <el-form ref="currentForm" status-icon :rules="rules" :model="form">
      <el-form-item prop="tel">
        <el-input v-model.trim="form.tel" placeholder="请输入您的手机号">
          <i slot="prefix" class="fa fa-phone-square input-ico"></i>
        </el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-input v-model.trim="form.code" placeholder="请输入手机验证码">
          <i slot="prefix" class="fa fa-shield input-ico"></i>
          <el-button slot="append" @click.native="captcha($event)" tabindex="-1">获取验证码</el-button>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="form.password" placeholder="请设置一个新密码，不少于6位">
          <i slot="prefix" class="fa fa-lock input-ico"></i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="btn-block" type="primary" @click="submit">确认</el-button>
      </el-form-item>
    </el-form>
  </div>


</section>
</template>

<script>
export default {
  name: 'RegPage',
  data () {
    return {
      form: {
        tel: '',
        code: '',
        password: '',
        member: ''
      },
      rules: {
        tel: [
          { required: true, message: '手机号不能为空', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.currentForm.validate(valid => {
        console.log(valid);
      });
    },

    /**
     * 发送验证码
     * @param {event} e
     */
    captcha(e) {
      this.$refs.currentForm.validateField('tel', err => !err && this.$fn.captcha(e));
    }

  }
}
</script>

<style lang="less">
.p-h-text {
  display: inline-block;
  line-height: 36px;
  font-size: 14px;
}
</style>
